<?php

	$moduleRequest = "";

	if (isset($_REQUEST['param']))
		$moduleRequest = $_REQUEST['param'];

	$pageUrl = "http://search.yahooapis.com/ImageSearchService/rss/imageSearch.xml?appid=yahoosearchimagerss&query=".urlencode($moduleRequest);
// 1. Get the rss from yahoo

	$pageHTML = getListenPage($pageUrl);

	$firstLink = getFirstItemUrl($pageHTML);

	$isgdUrl = getListenPage('http://is.gd/api.php?longurl='.urlencode($firstLink));

	echo $isgdUrl;

	function getListenPage($fvsWebUrl)
	{

		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL,$fvsWebUrl);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
		curl_setopt($ch, CURLOPT_TIMEOUT, 60);
		$ret = curl_exec ($ch);
		curl_close($ch);

		return $ret;
	}
	function getFirstItemUrl($pageHTML)
	{
		
		if ( preg_match_all ( '/<link>([^\"]*)<\/link>/',$pageHTML,$found))
		{

			return $found[1][1];
		}
		else
		{
			return "";
		}
	}
?> 
